package com.lagou.rpc.consumer.controller;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.pojo.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/rpc")
public class RpcClientController {

    /**
     * 创建service代理对象
     * @return
     */
    public IUserService createProxy() {
        IUserService userService = (IUserService) RpcClientProxy.createProxy(IUserService.class);
        return userService;
    }

    @RequestMapping("/queryUser/{id}")
    public void queryUser(@PathVariable Integer id) {
        IUserService userService = createProxy();
        User user = userService.getById(id);
        System.out.println(user);
    }
}
